package com.zc.portal.iface.service;

import com.zc.portal.domain.dto.SysUser;
import com.zc.portal.iface.repository.SysUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service(value = "sysUserDetailsService")
public class SysUserDetailsService implements UserDetailsService {

    @Autowired
    private SysUserRepository sysUserRepository;


    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {

        SysUser sysUser = sysUserRepository.querySysUserByCode(s);

        if (sysUser == null) {
            throw new UsernameNotFoundException("用户[" + s + "]不存在");
        }

        return sysUser;
    }
}
